package com.stu.thread._01_create3ways._03_callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Main {
  public static void main(String[] args) throws InterruptedException, ExecutionException {
    Callable<String> c1 = new MyThread01();
    FutureTask<String> ft1 = new FutureTask<>(c1);
    Thread t1 = new Thread(ft1, "线程一");

    FutureTask<String> ft2 = new FutureTask<>(() -> {
      for (int i = 0; i < 10; i++) {
        System.out.println(Thread.currentThread().getName() + "：" + i);
      }
      return "线程执行完毕";
    });
    Thread t2 = new Thread(ft2, "          线程二");

    t1.start();
    t2.start();

    Thread.sleep(1000);
    System.out.println("线程返回结果：" + ft1.get());
    System.out.println("线程返回结果：" + ft2.get());
  }
}
